/**
 * @file main.cpp
 * @author Hu Yumeng (3210103435@zju.edu.cn)
 * @brief 
 * @version 0.1
 * @date 2022-10-06
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include "DoubleLinkedList.h"
#define CRTDBG_MAP_ALLOC  
#include <stdlib.h>  
/**
 * @brief 遍历输出
 * 
 * @param _list 
 */
void printList(DoubleLinkedList<int>& _list)
{
  for (DoubleLinkedList<int>::iterator i = _list.begin(); i != _list.end(); i++) {
    cout << *i << endl;
  }
}

/**
 * @brief 查找函数
 * 查找成功返回该节点迭代器，失败返回该链表末端节点迭代器
 * @param _list 
 * @param _val 
 * @return DoubleLinkedList<int>::iterator 
 */
DoubleLinkedList<int>::iterator find(DoubleLinkedList<int>& _list, const int& _val)
{
  int f = 0;
  for (DoubleLinkedList<int>::iterator i = _list.begin(); i != _list.end(); i++)
  {
    if (*i == _val)
    {
      f = 1;
      cout << "查找成功,已返回该节点迭代器" << endl;
      return i;
    }
  }
  if (f == 0)
  {
    cout << "查找失败，已返回该链表末端节点迭代器" << endl;
    return _list.end();
  }
}

int main()
{
  /**
   * @brief 创建list对象
   * 
   */
  DoubleLinkedList<int>list;
  /**
   * @brief 插入1 2 3 4 5 
   * 
   */
  list.push_back(1);
  list.push_back(2);
  list.push_back(3);
  list.push_back(4);
  list.push_back(5);
  //cout<<list.size()<<endl;
  //int a = 10;

  //list.insert(list.begin(), 9);
  /**
   * @brief 打印
   * 
   */
  printList(list);
  DoubleLinkedList<int>::iterator itr;
  /**
   * @brief 查找数据3
   * 
   */
  itr = find(list, 3);
  /**
   * @brief 删除已找到节点对应的迭代器
   * 
   */
  list.erase(itr);
  /**
   * @brief 输出
   * 
   */
  printList(list);
  itr = find(list, 3);
  //list.insert(list.begin(), 1);
  
  //cout<<list.empty()<<endl;

  return 0;
}